package com.eaoa.uc.address.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.query.pub.PubAddressQuery;
import com.eaoa.query.pub.PubCityQuery;
import com.eaoa.uc.address.form.HRAddressCondition;
import com.eaoa.uc.address.form.HRAddressSearchForm;
import com.stony.core.util.CoreUtils;
public class HRAddressSearchAction extends EABaseAction{

	protected ActionForward doWork(ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response){
		
		HRAddressSearchForm sform = (HRAddressSearchForm) form;
		sform.initConditionPost();
		HRAddressCondition condition = (HRAddressCondition) sform.getCondition();
		
		PubAddressQuery query = new PubAddressQuery();	
		query.setAdcode(condition.getAdcode());
		query.setAdname(condition.getAdname());
		query.setCity(condition.getCity());
		query.setCountry(condition.getCountry());
		query.setCreatorname(condition.getCreatorname());
		query.setIslock(condition.getIslock());
		query.setLinkman(condition.getLinkman());
		query.setProvince(condition.getProvince());
		
		query.setOrder(condition.getSorttype(), condition.getSortfield());
		query.setPageRange(sform.getPageinfo());	
		query.execute();
		
		request.setAttribute("results", query.getResults());
		
		Long provinceno = CoreUtils.parseLong(condition.getProvince());
		if (provinceno!=null){
			PubCityQuery cityQuery = new PubCityQuery();
			cityQuery.setIsLock("N");
			cityQuery.setParentno(provinceno);
			cityQuery.setLayer(new Long(2));	
			cityQuery.noCheckOutOfMemory();
			cityQuery.setOrder();
			cityQuery.execute();
			request.setAttribute("city", cityQuery.getResults());				
		}
		
		Long cityno = CoreUtils.parseLong(condition.getCity());
		if (cityno!=null){
			PubCityQuery cityQuery = new PubCityQuery();
			cityQuery.setIsLock("N");
			cityQuery.setParentno(cityno);
			cityQuery.setLayer(new Long(3));	
			cityQuery.noCheckOutOfMemory();
			cityQuery.setOrder();
			cityQuery.execute();
			request.setAttribute("district", cityQuery.getResults());			
		}
		
		return mapping.findForward("success");
	}

}